package cn.ranko.run;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;

/**
 * Created by ZJ08 on 2016/8/1.
 * <p/>
 * tables.txt读取，用于mybatis生成文件
 */
public class TablesReader {


    public static void main(String[] args) {
        TablesReader tablesReader = new TablesReader();
        tablesReader.readShiroTxt();
    }



    public void readShopTxt(){
        try {
            String encoding = "UTF-8";
            File file = new File(TablesReader.class.getResource("/shop/tables.txt").getPath());
            if (file.isFile() && file.exists()) { //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file), encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    System.out.println("<table tableName=\"" + lineTxt + "\"" + " enableCountByExample=\"false\" enableSelectByExample=\"false\"\n" +
                            "               enableDeleteByExample=\"false\" enableUpdateByExample=\"false\" ></table>");
                }
                read.close();
            } else {
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
    }

    public void readShiroTxt(){
        try {
            String encoding = "UTF-8";
            File file = new File(TablesReader.class.getResource("/shiro/tables.txt").getPath());
            if (file.isFile() && file.exists()) { //判断文件是否存在
                InputStreamReader read = new InputStreamReader(
                        new FileInputStream(file), encoding);//考虑到编码格式
                BufferedReader bufferedReader = new BufferedReader(read);
                String lineTxt = null;
                while ((lineTxt = bufferedReader.readLine()) != null) {
                    System.out.println("<table tableName=\"" + lineTxt + "\"" + " enableCountByExample=\"false\" enableSelectByExample=\"false\"\n" +
                            "               enableDeleteByExample=\"false\" enableUpdateByExample=\"false\" ></table>");
                }
                read.close();
            } else {
                System.out.println("找不到指定的文件");
            }
        } catch (Exception e) {
            System.out.println("读取文件内容出错");
            e.printStackTrace();
        }
    }


}
